<template>
	<view class="content">
		<view class="head" v-if="nickName && avatarUrl">
			<image class="head_img" :src="avatarUrl" mode=""></image>
			<view class="head_right">
				<view class="head_name">{{nickName}}</view>
			</view>
		</view>
		<view class="head" v-else @tap="getUserInfo">
			<image class="head_img" src="../../static/img/head_img.png" mode=""></image>
			<view class="head_right">
				<view class="head_name">请登录</view>
			</view>
		</view>
		<view class="line_br"></view>
		<view class="select_box">
			<view class="select" @tap="toUrl('../order/order')">
				<view class="select_left">
					<image class="select_icon" src="../../static/img/order.png" mode=""></image>
					<view class="select_text">我的订单</view>
				</view>
				<view class="select_left">
					<image class="to_arrow" src="../../static/img/right.png" mode=""></image>
				</view>
			</view>
			<view class="select" @tap="toUrl('../collect/collect')">
				<view class="select_left">
					<image class="select_icon" src="../../static/img/shoucang.png" mode=""></image>
					<view class="select_text">我的收藏</view>
				</view>
				<view class="select_left">
					<image class="to_arrow" src="../../static/img/right.png" mode=""></image>
				</view>
			</view>
			<view class="select"  @tap="toUrl('../look/look')">
				<view class="select_left">
					<image class="select_icon" src="../../static/img/liulan.png" mode=""></image>
					<view class="select_text">我的浏览</view>
				</view>
				<view class="select_left">
					<image class="to_arrow" src="../../static/img/right.png" mode=""></image>
				</view>
			</view>
			<view class="select"  @tap="toUrl('../fangyuan/fangyuan')">
				<view class="select_left">
					<image class="select_icon" src="../../static/img/fangyuan.png" mode=""></image>
					<view class="select_text">我的发布</view>
				</view>
				<view class="select_left">
					<image class="to_arrow" src="../../static/img/right.png" mode=""></image>
				</view>
			</view>
			<!-- <view class="select" >
				<view class="select_left">
					<image class="select_icon" src="../../static/img/renzheng.png" mode=""></image>
					<view class="select_text">房东认证</view>
				</view>
				<view class="select_left">
					<view v-if="!isVerify" style="color: #888888;font-size: 32rpx;" @tap="toUrl('../certification/certification')">去认证</view>
					<view v-if="isVerify && status == 0" style="color: #F37B1D;font-size: 32rpx;">审核中</view>
					<view v-if="isVerify && status == 1" style="color: #007AFF;font-size: 32rpx;">已认证</view>
					<image class="to_arrow" v-if="!isVerify" @tap="toUrl('../certification/certification')" src="../../static/img/right.png" mode=""></image>
					<image class="to_arrow" v-if="isVerify" src="../../static/img/right.png" mode=""></image>
				</view>
			</view> -->
			<view class="select" @tap="toUrl('../feedback/feedback')">
				<view class="select_left">
					<image class="select_icon" src="../../static/img/fankui.png" mode=""></image>
					<view class="select_text">意见反馈</view>
				</view>
				<view class="select_left">
					<image class="to_arrow" src="../../static/img/right.png" mode=""></image>
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isVerify: false,
				status: 0,
				nickName: uni.getStorageSync("nickName"),
				avatarUrl: uni.getStorageSync("avatarUrl"),
				isLogin: false
			}
		},
		onShow() {
			if(this.nickName && this.avatarUrl){
				this.isLogin = true
				this.getStatus()
			}else{
				this.isLogin = false
			}
		},
		onLoad() {
			
		},
		methods: {
			getUserInfo(){
				let that = this
				uni.getUserProfile({
				    desc:'Wexin',     // 这个参数是必须的
				    success:res=>{
					   console.log("userRes",res)
					   uni.setStorageSync('nickName', res.userInfo.nickName);
					   uni.setStorageSync('avatarUrl', res.userInfo.avatarUrl);
					   this.nickName = res.userInfo.nickName
					   this.avatarUrl = res.userInfo.avatarUrl
					   uni.login({
							provider: 'weixin',
							success: (wxres => {
								console.log("wxres",wxres)
								that.$api.request('/api/web/wxlogin','',{
									code: wxres.code,
								}, failres => {
									uni.showToast({
										title: failres.msg,
										icon: "none"
									});
								}).then(res1 => {
									that.isLogin = true
									console.log("res1",res1)
									uni.setStorageSync('token', res1.data.token);
									uni.setStorageSync('openid', res1.data.openid);
									uni.setStorageSync('userId', res1.data.user.userId);
									that.getStatus()
								})
							})
						})
				   },
				   fail:err=>{
					   
				   }
			   })
			},
			getStatus(){
				let that = this
				that.$api.request('/api/authentication/list','',{
					userId: uni.getStorageSync("userId")
				}, failres => {
					uni.showToast({
						title: failres.msg,
						icon: "none"
					});
				}).then(res => {
					console.log(res)
					if(res.rows.length > 0){ //有提交
						that.isVerify = true
						if(res.rows && res.rows[0].status == 0){ //审核中
							that.status = 0
						}else{ //已认证
							that.status = 1
						}
					}else{ //未认证
						that.isVerify = false
					}
				})
			},
			toUrl(url){
				if(this.isLogin){
					uni.navigateTo({
						url: url
					})
				}else{
					this.getUserInfo()
				}
				
			}
		}
	}
</script>

<style lang="scss">
	.head{
		width: 90%;
		margin: 0 auto;
		display: flex;
		align-items: center;
		margin-bottom: 50rpx;
		padding-top: 20rpx;
		.head_img{
			width: 120rpx;
			height: 120rpx;
			border-radius: 60rpx;
			margin-right: 30rpx;
		}
		.head_name{
			font-size: 36rpx;
			color: #333333;
			font-weight: bold;
		}
		.head_desc{
			font-size: 32rpx;
			color: #715C33;
			margin-top: 20rpx;
		}
	}
	.line_br{
		width: 100%;
		height: 20rpx;
		background: #ebebeb;
	}
	.select_box{
		width: 100%;
		margin-top: 50rpx;
		.select{
			width: 96%;
			height: 100rpx;
			border-bottom: 1rpx solid #E6E6E6;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 0 auto;
			.select_left{
				display: flex;
				align-items: center;
				.select_icon{
					width: 40rpx;
					height: 40rpx;
					margin-right: 20rpx;
				}
			}
			.select_text{
				font-size: 32rpx;
				color: #656565;
				margin-right: 20rpx;
			}
			.to_arrow{
				width: 30rpx;
				height: 30rpx;
			}
		}
	}
</style>
